
package com.seekting.gongzhu.serversdk;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

import com.google.gson.Gson;
import com.seekting.gongzhu.sdk.DisConnectListener;
import com.seekting.gongzhu.sdk.Info;
import com.seekting.gongzhu.sdk.NetWorkHelper;
import com.seekting.gongzhu.sdk.Receiveable;
import com.seekting.gongzhu.sdk.gson.s2c.ErrorJsonS;

public class HostNetWorkHelper extends NetWorkHelper {

    public HostNetWorkHelper(Socket socket, DataOutputStream out, DataInputStream in, int index,
            DisConnectListener disconnectListener, Receiveable receiveable) {
        super(socket, out, in, index, disconnectListener, receiveable);
    }

    public void refuse() {
        refuse(Info.ErrorCode.UNKNOW);
    }

    public void refuse(int reson) {

        ErrorJsonS errorServerJson = new ErrorJsonS(reson);
        Gson gson = new Gson();
        String msg = gson.toJson(errorServerJson);
        send(msg);
        if (socket != null) {
            try {
                socket.close();
            } catch (IOException e) {
                // e.printStackTrace();
            }
        }
    }

}
